#include "../func.h"

typedef struct{
    pthread_mutex_t mutex;
    pthread_cond_t cond;
}data;

void* threadfunc(void* p)
{
    data* d = (data*)p;
    printf("I am child thread\n");
    pthread_mutex_lock(&d->mutex);
    pthread_cond_wait(&d->cond, &d->mutex);
    pthread_mutex_unlock(&d->mutex);
    printf("I am wakeup\n");
    pthread_exit(NULL);
}

int main()
{
    data t;
    pthread_mutex_init(&t.mutex, NULL);
    pthread_cond_init(&t.cond, NULL);
    pthread_t pthid;
    pthread_create(&pthid, NULL, threadfunc, &t);
    usleep(50);
    int ret;
    ret = pthread_cond_signal(&t.cond);

    printf("send signal success\n");
    pthread_join(pthid, NULL);
    printf("I am main thread\n");
    return 0;
}
